<?php
session_start();
if(!$_SESSION['logged']) 
  header("Location: ./index.php");

$state = 0;
$folder = $_SESSION['uploads'];
$processfolder = $_SESSION['processed'];
$completed = $_SESSION['completed'];
$home = $_SESSION['homedir'];

foreach($_POST as $a => $key){
	//print("key: ".$a." - value: ".$key."<br>");
	if($state == 1){
		//echo 'off<br>';
		unlink($folder.$key);
		if(file_exists ($processfolder.$key.".html")){
			unlink($processfolder.$key.".html");
			unlink($processfolder.$key.".html.modified");
		}
		$base = explode(".",$key); unset($base[count($base)-1]);$base = implode(".",$base);
		if(file_exists ($completed.$base.".html")){
			unlink($completed.$base.".html");
			unlink($completed.$base.".pdf");
			unlink($completed.$base.".pdf.modified");
		}
		if(file_exists($home.$key.".filter.txt")) {
			unlink($home.$key.".filter.txt");
		}
		if(file_exists($home.$key.".anonymize.txt")) {
			unlink($home.$key.".anonymize.txt");
		}
		$state = 0;
	}
	if($key == "on"){
		//echo 'on<br>';
		$state = 1;
	}
}
header("Location: ./index.php?p=file_management");
?>
